#ifndef _BufferManager
#define _BufferManager

#include <windows.h>	// for mutex handle
#include <stdio.h>		// for mutex handle
#include <time.h>
#include "Buffer.h"
#include "ParamManager.h"


namespace tlnet {

class BufferManager {

public:
	ParamManager eol;	// List of strings recognized as a completed line
						//   and what they should be chopped out and replaced with
	long count;	// used to slow down data coming in too fast
	Buffer *head, *tail;

	// insure thread-safe
	HANDLE mutex;

	// Constructor
	BufferManager(HANDLE /*mutex*/);
	// Deconstructor
	~BufferManager();

	// manage strings which indicate a completed line
	bool addEol(char* /*pattern*/, char* /*replace_with*/);
	bool delEol(char* /*pattern*/);

	// free up all memory used by link list
	void clear();

	bool addBytes(char*, int);

	// check if two Buffers need to be combined to get a full string
	void merge(Buffer*);

	// if there is a '\n' in the buffer
	bool isReady();

	// returns a pointer to the current available string,
	// or NULL if none is available
	char* getNext();

	// removes current available string
	void pop();

	// keeps the current available string saved & available at next eol
	void push();

	// display buffer link-list
	void dump();
};

}

#endif // _BufferManager